<?php
include("food_conf.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>学生注册</title>
  <script language="javascript"> 
    function information()
    {
		var student_ID = document.getElementById("student_ID").value;
		var student_pwd = document.getElementById("student_pwd").value;
		var pw2 = document.getElementById("pw2").value;
		if (student_ID == "")
			{alert("学生编号名不能为空！");}
		if (student_pwd == "")
	        {alert("密码不能为空！");}
		if (pw2 == "")
	        {alert("确认密码不能为空！");}
		if (student_pwd != pw2)
			{alert("两次密码不一样，请确认!");}
		if (student_ID.length > 10)
			{alert("学生编号长度不能大于10字符！");}
		if (student_pwd.length > 8)
			{alert("密码长度不能超过8个字符！");}
	}
</script>
 </head>
 <body>
  <form method="post" action="" onSubmit="return information()"> 
  <div align="center">学生编号：<br/>
<input type="text" name="student_ID" value="学生编号在10字符以内" onFocus="if(value=='学生编号在10字符以内') {value=''}"><br/>
密   码：<br/>
<font size="1px">(密码在8字符以内)</font><br/>
<input type="password" name="student_pwd"><br/>
确认密码：<br/>
<input type="password" name="pw2"><br/>
<hr>
<input type="submit" name="submit" value="注 册">
<input type="reset" name="reset" value="重 写">
</div>
</form>
</body>
</html>
<?php
$host = "127.0.0.1";
$user_name = "root";
$password = "000000";
if($_POST["submit"])
{
	$student_ID = $_POST['student_ID'];//获取编号
	$student_pwd = $_POST['student_pwd'];//获取密码

	$sql_s="select * from student where student_ID='$student_ID'";
	mysql_query($sql_s,$conn) or die ("该学生编号不存在：".mysql_error());
	$sql = "update student set student_pwd='$student_pwd' where  student_ID='$student_ID'";//将密码存入数据库
	$result = mysql_query($sql,$conn) or die ("注册用户失败: ".mysql_error());
	echo "<script language=javascript>alert('注册成功,进入登陆系统!');window.location = 'food_load_s.php'</script>";
}
?>